package com.example.shop.merchant.controller;

import com.example.shop.common.api.ResponseResult;
import com.example.shop.common.api.ServiceReturn;
import com.example.shop.common.enums.SessionAttributeKey;
import com.example.shop.order.dto.OrderBrowseInfo;
import com.example.shop.order.dto.OrderDetailInfo;
import com.example.shop.order.dto.OrderQueryParam;
import com.example.shop.order.service.BrowseOrderService;
import com.example.shop.pojo.Merchant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/merchant/order/browse")
public class OrderBrowseController {

    @Autowired
    BrowseOrderService browseOrderService;

    @GetMapping(value = "/{orderId}",consumes = MediaType.APPLICATION_JSON_VALUE)
    public ResponseResult<OrderDetailInfo> detailBrowseOrderInfo(HttpSession session,@RequestBody @PathVariable("orderId")long orderId){
        Merchant merchant = (Merchant) session.getAttribute(SessionAttributeKey.NOW_LOGIN_MERCHANT.getKey());
        ServiceReturn<OrderDetailInfo> result = browseOrderService.merchantObtainOrderInfo(merchant, orderId);
        return ResponseResult.auto(result.getStateCode(), result.getReturnData());
    }

    @PostMapping(value = "/",consumes = MediaType.APPLICATION_JSON_VALUE)
    public ResponseResult<List<OrderBrowseInfo>> browseOrder(HttpSession session, @RequestBody OrderQueryParam queryParam){
        Merchant merchant = (Merchant) session.getAttribute(SessionAttributeKey.NOW_LOGIN_MERCHANT.getKey());
        ServiceReturn<List<OrderBrowseInfo>> result = browseOrderService.merchantObtainOrderInfo(merchant, queryParam);
        return ResponseResult.auto(result.getStateCode(),result.getReturnData());
    }
}
